package io.xxx.omni.oss.custom

import com.google.gson.JsonObject
import io.xxx.omni.oss.core.PageSynchronizer
import io.xxx.omni.oss.sdk.AkcClient

/**
 * 爱库存
 */
// https://open.aikucun.com/docCenter
abstract class AkcSynchronizer : PageSynchronizer<JsonObject>() {

    protected abstract val interfaceName: String

    override fun getResponse(context: Context, pageNo: Int, containsTotal: Boolean): JsonObject {
        val request = buildRequest(context, pageNo)
        val client = applicationContext.getBean(AkcClient::class.java)
        val response = client.execute(store, interfaceName, request)
        if (!response["success"].asBoolean) {
            throwException(context, request, response)
        }
        return response["data"].asJsonObject
    }

    protected abstract fun buildRequest(context: Context, pageNo: Int): Map<String, Any>
}